class User {
  final String id;
  final String name;
  final String? email;
  final String? avatar;
  final String? role; // 'admin', 'teacher', 'student'
  final List<String> examHistoryIds; // 已参加考试的ID列表

  User({
    required this.id,
    required this.name,
    this.email,
    this.avatar,
    this.role,
    this.examHistoryIds = const [],
  });

  // 添加考试记录
  User addExamHistory(String examId) {
    return User(
      id: id,
      name: name,
      email: email,
      avatar: avatar,
      role: role,
      examHistoryIds: [...examHistoryIds, examId],
    );
  }

  // 示例用户
  static User sampleUser() {
    return User(
      id: 'user001',
      name: '测试用户',
      email: 'test@example.com',
      avatar: 'assets/default_avatar.png',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'email': email,
      'avatar': avatar,
      'role': role,
      'examHistoryIds': examHistoryIds,
    };
  }
}

class UserLog {
  final DateTime timestamp;
  final String userName;
  final String page;
  final String action; // "foreground" or "background"

  UserLog({
    required this.timestamp,
    required this.userName,
    required this.page,
    required this.action,
  });

  Map<String, dynamic> toJson() => {
    'timestamp': timestamp.toIso8601String(),
    'userName': userName,
    'page': page,
    'action': action,
  };

  factory UserLog.fromJson(Map<String, dynamic> json) => UserLog(
    timestamp: DateTime.parse(json['timestamp']),
    userName: json['userName'],
    page: json['page'],
    action: json['action'],
  );
}

// Student类已移至student_model.dart文件中 